package com.example.designmodel;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class FactoryActivity extends AppCompatActivity {
    public static void launch(Context context) {
        Intent intent = new Intent(context, FactoryActivity.class);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_factory);
        factory();
    }

    private void factory(){
        Creater creater = new ConcreateCreater();
        Product1 product1 = creater.createProduct(Product1.class);
        product1.method2();

        Product2 product2 = creater.createProduct(Product2.class);
        product2.method2();
    }

    public static abstract class Product {
        //产品类的公共方法
        public void method1() {
            //业务逻辑
        }

        //抽象方法
        public abstract void method2();

    }


    public static class Product1 extends Product{
        @Override
        public void method2() {
            Log.i("test","Product1");
        }
    }

    public static class Product2 extends Product{
        @Override
        public void method2() {
            Log.i("test","Product2");
        }
    }

    abstract static class Creater{
        public abstract <T extends Product> T createProduct(Class<T> product);


    }

    public static class ConcreateCreater extends Creater{
        @Override
        public <T extends Product> T createProduct(Class<T> product) {
            Product product1 = null;
            try {
                product1 = (Product) Class.forName(product.getName()).newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return (T) product1;
        }
    }


    //抽象工厂模式

    public static interface Human{
        public void getColor();
        public void taak();
        public void getSex();
    }

    public static abstract class AbstractWhiteHuman implements Human{
        @Override
        public void getColor() {
            Log.i("test","白种人的皮肤颜色是白色的");
        }

        @Override
        public void taak() {
            Log.i("test","白种人说话");
        }
    }

    public static abstract class AbstractBlackHuman implements Human{
        @Override
        public void getColor() {
            Log.i("test","黑种人的皮肤颜色是黑色的");
        }

        @Override
        public void taak() {
            Log.i("test","黑种人说话");
        }
    }

    public static abstract class AbstractYelloHuman implements Human{
        @Override
        public void getColor() {
            Log.i("test","黄种人的皮肤颜色是黄色的");
        }

        @Override
        public void taak() {
            Log.i("test","黄种人说话");
        }
    }

    public static class FemaleWhiteHuman extends AbstractWhiteHuman{
        @Override
        public void getSex() {
            Log.i("test","女性白种人");
        }
    }

    public static class MaleWhiteHuman extends AbstractWhiteHuman{
        @Override
        public void getSex() {
            Log.i("test","男性白种人");
        }
    }

    public static class FemaleBlackHuman extends AbstractBlackHuman{
        @Override
        public void getSex() {
            Log.i("test","女性黑种人");
        }
    }

    public static class MaleBlackHuman extends AbstractBlackHuman{
        @Override
        public void getSex() {
            Log.i("test","男性黑种人");
        }
    }

    public static class FemaleYelloHuman extends AbstractYelloHuman{
        @Override
        public void getSex() {
            Log.i("test","女性黄种人");
        }
    }

    public static class MaleYelloHuman extends AbstractYelloHuman{
        @Override
        public void getSex() {
            Log.i("test","男性黄种人");
        }
    }

    public static interface HumanFactory{
        public Human createYellowHuman();
        public Human createBlackHuman();
        public Human createWhiteHuman();
    }

    public static class FemalFactory implements HumanFactory{
        @Override
        public Human createYellowHuman() {
            return new FemaleYelloHuman();
        }

        @Override
        public Human createBlackHuman() {
            return new FemaleBlackHuman();
        }

        @Override
        public Human createWhiteHuman() {
            return new FemaleWhiteHuman();
        }
    }

    public static class Malefactory implements HumanFactory{
        @Override
        public Human createYellowHuman() {
            return new MaleYelloHuman();
        }

        @Override
        public Human createBlackHuman() {
            return new MaleBlackHuman();
        }

        @Override
        public Human createWhiteHuman() {
            return new MaleWhiteHuman();
        }
    }

    //抽象工厂类 2

    public static abstract class FemalHuman implements Human{
        @Override
        public void getSex() {
            Log.i("test","女性");
        }
    }

    public static abstract class MaleHuman implements Human{
        @Override
        public void getSex() {
            Log.i("test","男性");
        }
    }

    public static class YelloFemalHuman extends FemalHuman{
        @Override
        public void getColor() {
            Log.i("test","黄种人 黄颜色");
        }

        @Override
        public void taak() {
            Log.i("test","黄种人说中文");
        }
    }

    public static class YelloMalHuman extends MaleHuman{
        @Override
        public void getColor() {
            Log.i("test","黄种人 黄颜色");
        }

        @Override
        public void taak() {
            Log.i("test","黄种人说中文");
        }
    }

    public static class BlackFemalHuman extends FemalHuman{
        @Override
        public void getColor() {
            Log.i("test","黑种人 黑颜色");
        }

        @Override
        public void taak() {
            Log.i("test","黑种人说黑文");
        }
    }

    public static class BlackMalHuman extends MaleHuman{
        @Override
        public void getColor() {
            Log.i("test","黑种人 黑颜色");
        }

        @Override
        public void taak() {
            Log.i("test","黑种人说黑文");
        }
    }
    public static class WhiteFemalHuman extends FemalHuman{
        @Override
        public void getColor() {
            Log.i("test","白种人 白颜色");
        }

        @Override
        public void taak() {
            Log.i("test","白种人说白文");
        }
    }

    public static class WhitekMalHuman extends MaleHuman{
        @Override
        public void getColor() {
            Log.i("test","白种人 白颜色");
        }

        @Override
        public void taak() {
            Log.i("test","白种人说白文");
        }
    }

    public static interface HumanFactory2{
        Human createFemalHuman();
        Human createMalHuman();
    }

    public static class YelloHumanFacoty implements HumanFactory2{
        @Override
        public Human createFemalHuman() {
            return new YelloFemalHuman();
        }

        @Override
        public Human createMalHuman() {
            return new YelloMalHuman();
        }
    }



}
